package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.Service.MallSearchService;
import com.atguigu.gulimall.search.Vo.SearchParam;
import com.atguigu.gulimall.search.Vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping({"/","/list.html"})
    public String searchPage(SearchParam param, Model model, HttpServletRequest request){
        String queryString = request.getQueryString();
        param.set_queryString(queryString);
        SearchResult searchResult = mallSearchService.search(param);
        model.addAttribute("result",searchResult);
        model.addAttribute("param",param);
        return "list";
    }

}
